<?php

namespace App\Http\Controllers\Api;

use App\Banner;
use App\Distribution;
use App\Http\Services\FileManager;
use App\Http\Services\UserManager;
use App\User;
use App\UserInfo;
use App\VipRule;
use App\Withdraw;
use Illuminate\Bus\Dispatcher;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class OtherController extends Controller
{
    public function getBannerList(Request $request){
        $allBanner = Banner::orderBy("sort","asc")->orderBy("created_at","desc")->get();
        if(count($allBanner) > 0){
            foreach ($allBanner as $banner){
                /** @var Banner $banner */
                $banner->img_url = FileManager::getImgUrl($banner->img_id);
            }
        }

        return response()->json(["level"=>"success","message"=>"获取成功","data"=>$allBanner]);
    }

    public function getVipList(Request $request){
        $type = !is_null($request->get('type')) ? $request->get('type') : 'global_vip';
        $classifyId = !is_null($request->get('classify_id')) ? $request->get('classify_id') : 0;

        if($type == 'global_vip'){
            $allVips = VipRule::whereType($type)->orderBy('sort','asc')->orderBy('created_at','desc')->get();
        }elseif($type == 'classify_vip'){
            $allVips = VipRule::whereType($type)->whereClassifyId($classifyId)->orderBy('sort','asc')->orderBy('created_at','desc')->get();
        }else{
            return response()->json(['level' => 'error','message' => '系统错误']);
        }

        return response()->json(['level' => 'success','message' => '获取成功','data' => $allVips]);
    }
}
